<template>
  <BasicModal v-bind="$attrs" @register="registerModal" destroyOnClose :title="title" :width="800" :height="350" @ok="handleSubmit">
      <AttApplyResultList :applyId = "applyId" :applyCode="applyCode"></AttApplyResultList>
  </BasicModal>
</template>

<script lang="ts" setup>
    import {ref, computed, unref} from 'vue';
    import {BasicModal, useModalInner} from '/@/components/Modal';
    import {BasicForm, useForm} from '/@/components/Form/index';
    import {formSchema} from '../AttEventReg.data';
    import {saveOrUpdate,eventProcess} from '../AttEventReg.api';
    import AttApplyResultList from "/@/views/attendance/applyResult/AttApplyResultList.vue"
    // Emits声明
    const emit = defineEmits(['register','success']);
    const isUpdate = ref(true);
    const applyId = ref();
    const applyCode = ref();
    //表单配置
    const [registerForm, {setProps,resetFields, setFieldsValue, validate}] = useForm({
        //labelWidth: 150,
        schemas: formSchema,
        showActionButtonGroup: false,
        baseColProps: {span: 24}
    });
    //表单赋值
    const [registerModal, {setModalProps, closeModal}] = useModalInner(async (data) => {
      if(data.record?.id){
        applyId.value = data.record.id;
      }
      if(data.applyCode){
        applyCode.value = data.applyCode;
      }

        //重置表单
        setModalProps({confirmLoading: false,showCancelBtn:false,showOkBtn:false});

    });
    //设置标题
    const title = "审核流程";
    //表单提交事件
    async function handleSubmit(v) {
        try {
            let values = await validate();
            console.log(values)
            setModalProps({confirmLoading: true});

            if(values.isAudit==1){
                await eventProcess(values);
            }else{
                await saveOrUpdate(values, isUpdate.value);
            }
            //关闭弹窗
            closeModal();
            //刷新列表
            emit('success');
        } finally {
            setModalProps({confirmLoading: false});
        }
    }
</script>

<style lang="less" scoped>
	/** 时间和数字输入框样式 */
  :deep(.ant-input-number){
		width: 100%
	}

	:deep(.ant-calendar-picker){
		width: 100%
	}
</style>
